import * as THREE from 'three'
import { scene } from './universal'

//创建地面
const groundGeometry = new THREE.PlaneGeometry(500, 500)
const groundMaterial = new THREE.MeshLambertMaterial({ //材质
  color: 0xffffff,  //颜色
  side: THREE.DoubleSide //两面都能看到
})
const ground = new THREE.Mesh(groundGeometry, groundMaterial)
ground.receiveShadow = true //接收投影
ground.rotateX(-Math.PI / 2) //旋转90°，让它平铺在地面上

//生成随机数
const getRandomInt = (min, max) => {
  return Math.floor(Math.random() * (max - min + 1)) + min
}

//创建立方体盒子
const blocks = []
const createBox = () => {
  for (let i = 0; i < 500; i++) {
    const width = getRandomInt(1, 5)
    const height = getRandomInt(2, 6)
    const depth = getRandomInt(2, 4)
    const x = getRandomInt(-200, 200)
    const y = height / 2
    const z = getRandomInt(-200, 200)
    const boxGeometry = new THREE.BoxGeometry(width, height, depth)
    const boxMaterial = new THREE.MeshLambertMaterial({
      color: 0xff0000,
    })
    const mesh = new THREE.Mesh(boxGeometry, boxMaterial)
    mesh.position.set(x, y, z)
    blocks.push(mesh)
  }
}
createBox()

export { ground, blocks }